﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;
using Telerik.Web.UI;
using System.Collections.Specialized;
using System.Data;
using SalePartial.Utility;
using XunPan.Web.Globals;
using System.Text.RegularExpressions;
using SalePartial.BLL;
using SalePartial.BLL.SAServiceRef;
using SalePartial.Model;
using System.Data.SqlClient;
using System.IO;
using System.Xml;
using System.Text;

public partial class erjinzhipicture : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
          
    }
   
    protected void Button1_Click(object sender, EventArgs e)
    {
        string uppath = System.Web.HttpContext.Current.Server.MapPath("~/imgs/");
        XmlTextWriter writer = new XmlTextWriter(Server.MapPath("~/Images.xml"), Encoding.UTF8);
         writer.WriteStartDocument();
        writer.WriteStartElement("root");
        DeleteFolder(uppath);//清空存放图片的文件夹
        List<FamilyInfo> familie = SABLL.GetFamilyInfoNew();
        foreach (FamilyInfo item in familie)
        {
            Guid familyId = new Guid(item.ID.ToString());
            FamilyInfo m_familyInfo = SABLL.GetFamilyInfo(familyId);
            FamilyAttrInfo familyAttr = SABLL.GetFamilyAttrInfo(m_familyInfo.ID);
            if (familyAttr == null)
            {
                SABLL.ShowErrMsg(this, SABLL.GetLastErrMsg());
                return;
            }
            string name = item.Name;
            System.IO.MemoryStream ms = new System.IO.MemoryStream(familyAttr.ModelPicBinary);
            System.Drawing.Image img = System.Drawing.Image.FromStream(ms);
            img.Save(uppath + name + ".jpg");
            writer.WriteStartElement("OneItem");           
            writer.WriteElementString("title", name);        
            writer.WriteElementString("imgurl", "http://222.73.205.208:83/imgs/"+name+".jpg");           
            writer.WriteElementString("gotolink", "http://222.73.205.208:83/Default4.aspx?familyId="+item.ID);
            writer.WriteElementString("id", item.ID.ToString());
            writer.WriteEndElement();
            
        }
        writer.WriteEndElement();
        writer.WriteEndDocument();
        writer.Close();
        Response.Write("<script language=javascript> alert('柜台展示产品更新成功！');</script>");
    }
    public static void DeleteFolder(string dir)
    {
        foreach (string d in Directory.GetFileSystemEntries(dir))
        {
            if (File.Exists(d))
            {
                FileInfo fi = new FileInfo(d);
                if (fi.Attributes.ToString().IndexOf("ReadOnly") != -1)
                    fi.Attributes = FileAttributes.Normal;
                File.Delete(d);//直接删除其中的文件  
            }
        }
    }
}